export interface FieldOption {
  key?: number;
  label: string;
  visible: boolean;
  prop?: string;
  children?: Array<FieldOption>;
}

// 定义ValidationRule类型
export interface ValidationRule {
  required?: boolean;
  message?: string;
  trigger?: string;
  pattern?: RegExp;
  min?: number;
  max?: number;
  validator?: (value: any, row: Record<string, any>, field: FieldOption) => boolean | string;
}

// 2. 修复TableRowEditorProps接口
export interface TableRowEditorProps {
  // 绑定的值
  modelValue: string | number | Date | Array<any> | null | undefined;
  // 字段配置
  field: FieldOption;
  // 行数据
  row: Record<string, any>;
  // 组件类型：input、select、date 等
  components: string;
  // 选项数据（用于select组件）
  selectOptions?: Array<any>;
  // 是否禁用
  disabled?: boolean;
  // 验证规则 - 现在支持数组或对象格式
  rules?: ValidationRule | ValidationRule[];
  // 父组件传入的错误信息
  parentError?: string;
  // 是否显示错误信息
  showError?: boolean;
}

// 3. 修复TableRowEditorEmits接口
export interface TableRowEditorEmits {
  (e: 'update:modelValue', value: any): void;

  (e: 'blur', row: Record<string, any>, field: FieldOption): void;

  (e: 'input', value: any, row: Record<string, any>, field: FieldOption): void;

  (e: 'clear', row: Record<string, any>, field: FieldOption): void;

  (e: 'validate', isValid: boolean, message: string, row: Record<string, any>, field: FieldOption): void;

  (e: 'error-change', hasError: boolean): void;
}

// 类型定义
export interface Cell {
  name: string;
  id: string | number;
  type: string;
  brandId: string | number;
  customerId: string | number;
}

export interface Column {
  name: string;
  permissions?: {
    addLeft?: boolean; // 左侧添加列权限
    addRight?: boolean; // 右侧添加列权限
    delete?: boolean; // 删除列权限
    clear?: boolean; // 清空列权限
  };
}

export interface ContextMenuState {
  visible: boolean;
  x: number;
  y: number;
  columnIndex: number;
}

export interface MenuOption {
  label: string;
  action: string;
  icon: string;
}

// 拖拽状态接口
export interface DragState {
  isDragging: boolean;
  isMovingCells: boolean;
  dragStartCell: { row: number; col: number; x: number; y: number };
  dragPreview: { visible: boolean; x: number; y: number; width: number; height: number };
  draggedCellsData: { row: number; col: number; data: Cell }[]; // 修改为 name 字段
  dragDataRange: { minRow: number; maxRow: number; minCol: number; maxCol: number };
  moveTarget: { row: number; col: number };
  selectedCells: Set<string>;
}

export interface TooltipState {
  visible: boolean;
  content: string;
  x: number;
  y: number;
}

export interface VirtualScrollState {
  scrollTop: number;
  startIndex: number;
  offsetY: number;
}

export interface TableState {
  tableData: Cell[][];
  columns: Column[];
}

export interface DragItem {
  id: number;
  data: number[];
  label: string;
}
